<template>
  <div class="pagination">
    <div class="numbox" style="display: flex">
      <div>
        现<span>{{ pageData.totalRows }}</span
        >条数据
      </div>
      <div>
        共<span>{{ pageData.totalPages }}</span
        >页
      </div>
    </div>
    <div class="pagination-wrapper">
      <el-dropdown trigger="click" :tabindex="current" @command="handleCommand">
        <div class="el-dropdown-link dropdown-wrapper">
          {{ current }}
          <i class="el-icon-arrow-down el-icon--right"></i>
        </div>
        <el-dropdown-menu slot="dropdown">
          <el-dropdown-item
            :command="item"
            v-for="item in pageData.totalPages"
            :key="item"
            >{{ item }}</el-dropdown-item
          >
        </el-dropdown-menu>
      </el-dropdown>
      <el-pagination
        class="el-pagination"
        background
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="current"
        :page-size="pageData.rowSize"
        layout="prev, pager, next"
        :total="pageData.totalRows"
      >
      </el-pagination>
    </div>
  </div>
</template>
<script>
export default {
  props: {
    pageData: {
      type: Object,
      default: {}
    }
  },
  watch: {
    pageData: {
      handler(v) {
        this.current = v.index;
      },
      immediate: true,
      deep: true
    }
  },
  data() {
    return {
      current: 1
    };
  },
  methods: {
    handleSizeChange(index) {
      console.log("page-size改变", index, this.pageData);
    },
    handleCurrentChange(index) {
      console.log("current修改", index, this.pageData);
      this.current = index;
      this.$emit("jump", index);
    },
    currentPage(index) {
      console.log("page改变", index);
    },
    handleCommand(index) {
      this.current = index;
      this.$emit("jump", index);
    }
  }
};
</script>
<style scoped>
/* 分页 */
.pagination {
  width: 100%;
  position: absolute;
  bottom: 0.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 2.3rem;
  box-sizing: border-box;
}
.pagination-wrapper {
  display: flex;
  align-items: center;
}
.dropdown-wrapper {
  width: 40px;
  padding: 4px;
  background-color: #fff;
  box-shadow: 2px 2px 2px 0px #d4d4d4;
  border-radius: 7px;
  font-size: 13px;
  display: flex;
  justify-content: center;
  align-items: center;
}

>>> .el-pagination.is-background .el-pager li:not(.disabled).active {
  background-color: #f78c52;
  border-radius: 7px;
  color: #fff;
}

>>> .el-pagination.is-background .btn-prev {
  background-color: #fff;
  box-shadow: 2px 2px 2px 0px #d4d4d4;
  border-radius: 7px;
}

>>> .el-pagination.is-background .el-pager li {
  background-color: #fff;
  box-shadow: 2px 2px 2px 0px #d4d4d4;
  border-radius: 7px;
}

>>> .el-pagination.is-background .btn-next {
  background-color: #fff;
  box-shadow: 2px 2px 2px 0px #d4d4d4;
  border-radius: 7px;
}

.pagination .numbox div:first-child {
  margin-right: 1.3rem;
}

.pagination .numbox {
  font-size: 1.6rem;
  color: #827070;
}

.pagination .numbox span {
  color: #f78c52;
  font-size: 1.6rem;
  padding: 0 0.4rem;
  font-weight: bold;
}

.el-pagination.is-background .btn-next,
.el-pagination.is-background .btn-prev,
.el-pagination.is-background .el-pager li {
  min-width: 3rem;
}

.el-pager li {
  height: 3rem;
  line-height: 3rem;
  font-size: 1.4rem;
}
.el-pagination button,
.el-pagination span:not([class*="suffix"]) {
  display: inline-block;
  font-size: 1.4rem;
  height: 3rem;
  line-height: 3rem;
}
</style>
